package com.itmayiedu.dao;

import com.itmayiedu.entity.UserEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author cht 【wonderfor@vip.qq.com】
 * @Date 2018/10/19
 */
@Mapper
public interface MemberDao {

    @Select("SELECT id,username,password,phone,email,openid,created,updated FROM mb_user WHERE id = #{userId}")
    UserEntity findByID(@Param("userId") Long userId);

    @Insert("INSERT INTO `mb_user` (username,password,phone,email,created,updated) VALUES (#{username}, #{password},#{phone},#{email},#{created},#{updated});")
    Integer insertUser(UserEntity userEntity);

    @Select("SELECT id,username,password,phone,email,openid,created,updated FROM mb_user WHERE username=#{username} and password=#{password}")
    UserEntity login(@Param("username")String username, @Param("password")String password);

    @Select("SELECT id,username,password,phone,email,openid,created,updated FROM mb_user WHERE openid = #{openid}")
    UserEntity findByOpenIdUser(@Param("openid") String openid);

    @Update(("UPDATE mb_user set openid=#{openid} where id = #{userId}"))
    Integer updateUser(@Param("openid") String openid, @Param("userId") Integer id);
}
